#include <vector>
using namespace std;

class NumArray {
  vector<int> numSum;

public:
  NumArray(vector<int> &nums) {
    numSum.resize(nums.size());
    numSum[0] = nums[0];
    int length = numSum.size();
    for (int i = 1; i < length; ++i) {
      numSum[i] = numSum[i - 1] + nums[i];
    }
  }

  int sumRange(int left, int right) {
    if (left > 0) {
      return this->numSum[right] - this->numSum[left - 1];
    } else {
      return this->numSum[right];
    }
  }
};
